package com.zhiwei.msf.infra.oauth.mapper;

import com.zhiwei.msf.infra.oauth.entity.AuthorityInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface AuthorityInfoMapper {

    @Select(" select T4.* from user_info T1, user_role T2, role_authority T3, authority_info T4 where \n" +
            "T1.uuid=#{uuid} and T2.user_id = T1.uuid and T2.role_id = T3.role_id and T3.authority_id = T4.uuid")
    @Results({
            @Result(property = "uuid", column = "uuid", javaType = String.class),
            @Result(property = "parentId", column = "parent_id", javaType = String.class),
            @Result(property = "name", column = "name", javaType = String.class),
            @Result(property = "ename", column = "ename", javaType = String.class),
            @Result(property = "url", column = "url", javaType = String.class),
            @Result(property = "description", column = "description", javaType = String.class),
            @Result(property = "createTime", column = "create_time", javaType = Date.class),
            @Result(property = "updateTime", column = "update_time", javaType = Date.class)
    })
    List<AuthorityInfo> selectByUserId(@Param("uuid") String uuid);

    @Select("SELECT * FROM authority_info")
    @Results({
            @Result(property = "uuid", column = "uuid", javaType = String.class),
            @Result(property = "parentId", column = "parent_id", javaType = String.class),
            @Result(property = "name", column = "name", javaType = String.class),
            @Result(property = "ename", column = "ename", javaType = String.class),
            @Result(property = "url", column = "url", javaType = String.class),
            @Result(property = "description", column = "description", javaType = String.class),
            @Result(property = "createTime", column = "create_time", javaType = Date.class),
            @Result(property = "updateTime", column = "update_time", javaType = Date.class)
    })
    List<AuthorityInfo> queryAllAuthorities();
}